<template>
  <div>
    <el-text class="mx-1 marb-20" size="large">采购产品信息</el-text>
    <el-form
      :inline="true"
      :model="formInline"
      label-width="120px"
      class="demo-form-inline"
    >
      <el-form-item label="产品编码/名称">
        <el-input
          v-model="formInline.user"
          placeholder="支持单个查询或块粘贴"
          clearable
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary">查看全部</el-button>
      </el-form-item>
    </el-form>
    <el-form ref="formData" :model="formData" class="formData">
      <el-table :data="tableData" table-layout="fixed" show-summary>
        <el-table-column prop="brand" label="* 品牌">
          <template #default="props">
            <el-form-item prop="brand">
              <el-input v-model="props.row.brand"></el-input>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column prop="product_code" label="* 产品编码">
          <template #default="props">
            <el-form-item prop="product_code">
              <el-input v-model="props.row.product_code"></el-input>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column prop="product_name" label="* 产品名称">
          <template #default="props">
            <el-form-item prop="product_name">
              <el-input v-model="props.row.product_name"></el-input>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column prop="selling_price" label="售价">
          <template #default="props">
            <el-form-item prop="selling_price">
              <el-input v-model="props.row.selling_price"></el-input>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column prop="purchase_quantity" label="* 采购数量">
          <template #default="props">
            <el-form-item prop="purchase_quantity">
              <el-input v-model="props.row.purchase_quantity"></el-input>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column prop="purchase_price" label="采购金额">
          <template #default="props">
            <el-form-item prop="purchase_price">
              <el-input v-model="props.row.purchase_price"></el-input>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column prop="text" label="备注">
          <template #default="props">
            <el-form-item prop="text">
              <el-input v-model="props.row.text"></el-input>
            </el-form-item>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" width="120">
          <template #default="props">
            <vab-icon
              icon="add-circle-line"
              class="icon_color"
              @click="handleClick('add', props.$index)"
            />
            <vab-icon
              icon="delete-bin-5-line"
              @click="handleClick('remove', props.$index)"
            />
          </template>
        </el-table-column>
      </el-table>
    </el-form>
  </div>
</template>

<script lang="ts" setup>
  import { reactive } from 'vue'
  import { _TableData, _TableData_add, _TableData_remove } from './tools'
  const formInline = reactive({
    user: '',
    region: '',
    date: '',
  })

  const formData = reactive({})
  const tableData = _TableData

  const handleClick = (type: string, index = 0) => {
    if (type == 'add') {
      _TableData_add(index)
    }
    if (type == 'remove') {
      _TableData_remove(index)
    }
  }
</script>

<style lang="scss" scoped>
  .marb-20 {
    display: inline-block;
    margin-bottom: 20px;
  }
  .formData {
    :deep() {
      .el-form-item {
        margin-bottom: 0px;
      }
    }
    .icon_color {
      color: #0967f4;
      margin-right: 4px;
    }
  }
</style>
